/*    */ package com.zimbra.cs.dav.service.method;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.cs.dav.DavContext;
/*    */ import com.zimbra.cs.dav.DavContext.RequestProp;
/*    */ import com.zimbra.cs.dav.DavElements.CardDav;
/*    */ import com.zimbra.cs.dav.DavException;
/*    */ import com.zimbra.cs.dav.carddav.Filter;
/*    */ import com.zimbra.cs.dav.carddav.Filter.PropFilter;
/*    */ import com.zimbra.cs.dav.resource.AddressObject;
/*    */ import com.zimbra.cs.dav.resource.AddressbookCollection;
/*    */ import com.zimbra.cs.dav.resource.DavResource;
/*    */ import com.zimbra.cs.dav.service.DavResponse;
/*    */ import java.util.Collection;
/*    */ import java.util.Iterator;
/*    */ import org.dom4j.Document;
/*    */ import org.dom4j.Element;
/*    */ import org.dom4j.QName;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class AddressbookQuery
/*    */   extends Report
/*    */ {
/*    */   public void handle(DavContext ctxt)
/*    */     throws DavException, ServiceException
/*    */   {
/* 45 */     DavResource rsc = ctxt.getRequestedResource();
/* 46 */     if (!(rsc instanceof AddressbookCollection)) {
/* 47 */       throw new DavException("not an addressbook resource", 400, null);
/*    */     }
/* 49 */     Element query = ctxt.getRequestMessage().getRootElement();
/* 50 */     if (!query.getQName().equals(DavElements.CardDav.E_ADDRESSBOOK_QUERY))
/* 51 */       throw new DavException("msg " + query.getName() + " is not addressbook-query", 400, null);
/* 52 */     Element f = query.element(DavElements.CardDav.E_FILTER);
/* 53 */     if (f == null)
/* 54 */       throw new DavException("msg " + query.getName() + " is missing filter", 400, null);
/* 55 */     Filter filter = new Filter.PropFilter((Element)f.elementIterator().next());
/* 56 */     Collection<AddressObject> contacts = filter.match(ctxt, (AddressbookCollection)rsc);
/* 57 */     DavContext.RequestProp reqProp = ctxt.getRequestProp();
/* 58 */     DavResponse resp = ctxt.getDavResponse();
/* 59 */     resp.createResponse(ctxt);
/* 60 */     for (AddressObject c : contacts) {
/* 61 */       resp.addResource(ctxt, c, reqProp, false);
/*    */     }
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/dav/service/method/AddressbookQuery.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */